<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>会议纪要</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="100px" ref="editForm">
          <el-form-item label="纪要文件:">
            <el-upload
                class="upload-demo"
                :action="$uploadImg"
                :on-remove="handleRemove"
                :on-success="handleSuccess"
                :before-upload="beforeAvatarUpload"
                accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
                multiple
                :limit="1">
              <el-button size="small" class="el-icon-upload">点击上传相应文件</el-button>
              <div slot="tip" class="el-upload__tip">上传word文件</div>
            </el-upload>
            <el-button size="small" @click="priveWord" v-if="infoForm.word">预览文件</el-button>
          </el-form-item>
          <el-form-item label="纪要照片:">
            <el-upload
                class="addicon"
                accept="image/png, image/jpeg"
                list-type="picture-card"
                :action="$uploadImg"
                :file-list="fileList"
                :limit="100"
                :on-success="handleSuccessImg"
                :on-remove="handleRemoveImg"
                :before-upload="beforeAvatarUploadImg">
              <i class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="纪要记录:">
            <el-input
                type="textarea"
                placeholder="请输入纪要记录"
                v-model="infoForm.body"
                maxlength="1000"
                show-word-limit
                rows="8"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <!--      <div class="commentBody">-->
      <!--        <el-form :model="editForm" label-width="100px" ref="editForm" v-if="editForm">-->
      <!--          <el-form-item label="任务文件:">-->
      <!--            <el-button size="small" v-if="editForm.appendix" @click="priveWord">预览文件</el-button>-->
      <!--            <span v-else>无</span>-->
      <!--          </el-form-item>-->
      <!--        </el-form>-->
      <!--      </div>-->
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button @click="saveImg" size="small" type="primary">确定并保存</el-button>
      </div>
    </div>
    <div class="iframeBoxBody" v-if="iframeState">
      <img src="@/assets/imageAdmin/closeimg.png" alt="" @click.stop="iframeState=false">
      <webview id="foo" :src="iframeSrc" style="display:inline-flex; width:840px; height:680px;background:#fff;"
               plugins v-if="iframeState"></webview>
    </div>
    <AuxiliaryModule @getInformation="getInformation" typeData="videoMeet_description"></AuxiliaryModule>
  </div>
</template>

<script>
export default {
  props: ['visible', 'meetId'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      iframeSrc: false,
      fileList: [],
      infoForm: {
        word: '',
        pic: '',
        body: ''
      },
      uploadPic: [],
      iframeState: false,
      httpUrlInfo: ''
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.InitFn()
        this.listFn()
      } else {
        this.fileList = [];
        this.uploadPic = [];
        this.infoForm = {
          word: '',
          pic: '',
          body: ''
        }
      }
    }
  },
  created() {

  },
  methods: {
    InitFn() {
      this.$fetch(this.api.system_setting, {}).then(res => {
        if (!res.code) {
          console.log(res)
          this.httpUrlInfo = res.vo.url;

        } else {

        }
      })
    },
    listFn() {
      this.$fetch(this.api.videoMeet.fileEdit, {meeting_id: this.meetId}).then(res => {
        if (!res.code) {
          if (res.vo) {
            let data_ = res.vo.pic ? res.vo.pic.split(',') : []
            for (let i in data_) {
              let url_ = {}
              url_.url = data_[i]
              this.fileList.push(url_);
              this.uploadPic.push(data_[i]);
            }
            this.infoForm.word = res.vo.word
            this.infoForm.body = res.vo.body
          }
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    async saveImg() {
      if (!this.uploadPic.length && !this.infoForm.word && !this.infoForm.body) {
        this.$message.error('选填纪要照片/纪要文件/纪要记录')
        return
      }
      let data_ = {};
      data_.pic = this.uploadPic.join(','); // 图片
      data_.word = this.infoForm.word; // 文件
      data_.meeting_id = this.meetId;
      data_.body = this.infoForm.body
      let data = await this.$post(this.api.videoMeet.fileAdd, data_)
      if (!data.code) {
        this.$message.success(data.msg)
        this.closePOpup()
      } else {
        this.$message.error(data.msg)
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    priveWord() {
      if (this.httpUrlInfo) {
        this.iframeSrc = 'https://view.officeapps.live.com/op/view.aspx?src=' + this.httpUrlInfo + this.infoForm.word
        this.iframeState = true
      } else {
        this.$message.error('学校还未设置域名，请联系管理员！')
      }
    },
    beforeAvatarUpload(file) {
      console.log('上传数据excel：', file)
    },
    handleSuccess(response) {
      this.infoForm.word = response.data.pic
    },
    handleRemove(file, fileList) {
      console.log('移除', file, fileList)
      this.infoForm.word = ''
    },
    handleRemoveImg(file, fileList) {
      let index_ = this.uploadPic.indexOf(file.response.data.name)
      this.uploadPic.splice(index_, 1)
    },
    handleSuccessImg(response) {
      this.uploadPic.push(response.data.name)
    },
    beforeAvatarUploadImg(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isLt2M
    },    // 同步数据
    getInformation(option) {
      console.log('收到的数据', option)
      for (let item of option) {
        if (item.type === 'textarea') {
          this.infoForm.body = item.value
        }
      }
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 70%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


